package com.xc.freeapp.service.impl;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
import com.github.miemiedev.mybatis.paginator.domain.PageList;
import com.github.miemiedev.mybatis.paginator.domain.Paginator;
import com.xc.freeapp.dao.MessagesDao;
import com.xc.freeapp.dao.dataSource.DBContextHolder;
import com.xc.freeapp.entity.Messages;
import com.xc.freeapp.service.MessagesService;


@Service
public class MessagesSerciceImpl  implements  MessagesService{
  
	Logger log = Logger.getLogger(this.getClass());
	
	@Autowired
	private  MessagesDao   messagesdao;
	
	/**
	 * 系统消息查询
	 */
	public  List<Messages> getmessage(String businessId,String userid,PageBounds pageBounds) {
		DBContextHolder.switchDataSourceR();//切换数据源
		Map<String, String>  map=new HashMap<String, String>();
		map.put("businessId", businessId);
		map.put("userid", userid);
		
		List<Messages> messageslist = messagesdao.querymessages(map,pageBounds);
		
		return messageslist;
	}
	@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
	public int delmessages(String id) {
		DBContextHolder.switchDataSourceRW();//切换数据源
	        int j=messagesdao.delmessages(id);
		return j;
	}
	@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
	public int updamessagesstatus(String id) {
		DBContextHolder.switchDataSourceRW();//切换数据源
		
         int j=messagesdao.updamessagesstatus(id);
       
		return j;
	}
	public Messages getMessageByid(Integer mid) {
		// TODO Auto-generated method stub
		DBContextHolder.switchDataSourceRW();//切换数据源
		return messagesdao.selectByPrimaryKey(mid);
	}
	public List<Messages> getNotice(Integer businessId, Integer userid,
			PageBounds pageBounds) {
		// TODO Auto-generated method stub
		DBContextHolder.switchDataSourceRW();//切换数据源
		Map<String, Object>  map=new HashMap<String, Object>();
		map.put("businessId", businessId);

		
		List<Messages> messageslist = messagesdao.querymessagesBytype(map, pageBounds);
		
		return messageslist;
	}
	public List<Messages> getNoticeV2(Integer businessId, Integer userid,
			PageBounds pageBounds) {
		// TODO Auto-generated method stub
		DBContextHolder.switchDataSourceRW();//切换数据源
		Map<String, Object>  map=new HashMap<String, Object>();
		map.put("businessId", businessId);
		map.put("userid", userid);
		
		List<Messages> messageslist = messagesdao.querymessagesBytypeV2(map, pageBounds);
		
		return messageslist;
	}
}
